import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:ls_work/bad_event/ui/bad_event_list_page.dart';
import 'package:ls_work/doctor_patrol/view_model/doctor_patrol_record_view_model.dart';
import 'package:ls_work/res/colors.dart';
import 'package:ls_work/util/ext_utils.dart';

import 'create_doctor_patrol_page.dart';
class DoctorPatrolRecordPage extends BaseStatefulMvvmWidget{
  @override
  State<StatefulWidget> createState() => _DoctorPatrolRecordState();

}

class _DoctorPatrolRecordState extends BaseMvvmListState<DoctorPatrolRecordViewModel,DoctorPatrolRecordPage>{
  @override
  Widget buildRootView(BuildContext context, Widget loadingContentWidget) {
    return Scaffold(
      backgroundColor: Colours.bg_color,
      appBar: AppBar(title: Text('巡诊记录'),),
      body: Column(
        children: [
          Row(
            children: [
              CommonText('巡诊时间'),

              CommonText(vm?.startDateStr??"",textSize: 14).addToContainer(
                alignment: Alignment.center,
                decoration: BoxDecoration(
                  color: Colours.bg_color,
                  borderRadius: 4.borderRadius
                ),
                padding: EdgeInsets.symmetric(vertical: 10)
              ).setWeight(1),

              CommonText("——"),

              CommonText(vm?.endDateStr??"",textSize: 14).addToContainer(
                  alignment: Alignment.center,
                  decoration: BoxDecoration(
                      color: Colours.bg_color,
                      borderRadius: 4.borderRadius
                  ),
                  padding: EdgeInsets.symmetric(vertical: 10)
              ).setWeight(1),
            ].insertWidget(SizedBox(width: 5,)),
          ).addToContainer(
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: 4.borderRadius
            ),
            padding: EdgeInsets.symmetric(horizontal: 10,vertical: 5),
            margin: EdgeInsets.only(left: 16,right: 16,top: 12)
          ).onTap((){
            viewModel.chooseRangeTime();
          }),
          
          loadingContentWidget.setWeight(1),

          TextButton(onPressed: () async {
            var data = await Go().push(CreateDoctorPatrolPage());
            if(data!=null){
              viewModel.requestRefresh();
            }
          }, child: CommonText('新增',textColor: Colors.white),style: badEventButtonStyle,).addToContainer(
            margin: EdgeInsets.only(left: 16,right: 16,top: 12,bottom: 20)
          )
        ],
      ),
    );
  }

  @override
  Widget createItemWidget(int index) {
    var item = viewModel.listItems[index];
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Row(
          crossAxisAlignment: CrossAxisAlignment.end,
          children: [
            CommonText(item.elderName,textSize: 17,fontWeight: FontWeight.bold),
            SizedBox(width: 10,),
            CommonText('${item.roomNo}')
          ],
        ),
        CommonText('时间：${item.healthReport?.collectionTime}'),
        CommonText('体温：${item.healthReport?.temperature.toStringOrNull()??""}°C'),
        CommonText('血氧饱和度：${item.healthReport?.oxygen.toStringOrNull()??""}%'),
        CommonText('脉搏：${item.healthReport?.pulseRate.toStringOrNull()??""}次/分'),
        CommonText('心率：${item.healthReport?.heart.toStringOrNull()??""}次/分'),
        CommonText('血压：${item.healthReport?.low.toStringOrNull()??""}/${item.healthReport?.high.toStringOrNull()??""}mmHg'),
        CommonText('内容：${item.remark??""}'),
        CommonText('执行人：${item.executor??""}'),

      ].insertWidget(SizedBox(height: 8,)),
    ).addToContainer(
      decoration: BoxDecoration(
        color: Colors.white,borderRadius: 6.borderRadius
      ),
      padding: EdgeInsets.symmetric(horizontal: 10,vertical: 12)
    );
  }

  @override
  Widget get separatorDivider => SizedBox(height: 12,);

  @override
  EdgeInsets get listPadding => EdgeInsets.symmetric(horizontal: 16,vertical: 12);

  @override
  DoctorPatrolRecordViewModel createViewModel() {
    return DoctorPatrolRecordViewModel(context);
  }

  @override
  bool get canPullUp => true;
}